home *** CD-ROM | disk | FTP | other *** search
- #ifndef __BALLOONS__
- #include <Balloons.h>
- #endif
-
- #ifndef __CTLHANDLER__
- #define __CTLHANDLER__
-
- #ifndef __TYPES__
- #include <Types.h>
- #endif
-
- #ifndef __EVENTS__
- #include <Events.h>
- #endif
-
- #ifndef __WINDOWS__
- #include <Windows.h>
- #endif
-
- #define kScrollEvent 0x8000
-
-
-
- short IsCtlEvent(WindowPtr window, EventRecord *event, ControlHandle *ctl, short *action);
- /*
- ** ¶ Let a control handle the event.
- **
- ** INPUT: window Window that owns the controls that the event is to be applied to
- ** event The event to apply to the controls
- ** OUTPUT: ctl The control that ate the event. If you don't care, pass in nil
- ** action The action of the control that ate the event. If you don't
- ** care, pass in nil. Note that the action varies with the control
- ** type.
- ** RESULT: short The control ID of the control that ate the event. If no control
- ** ate the event, then 0 is returned. If a document scrollbar ate
- ** the event, then kScrollEvent is returned.
- **
- ** The purpose of this function is to simplify and standardize control handling within
- ** a window. Given an event, just call IsCtlEvent, and if it returns a non-0 value,
- ** the value represents the ctlID of the control.
- ** NOTE: Even if the AppsToGo editor ctlID value is 0, IsCtlEvent will return a
- ** non-0 value. The value in this case represents the positional value of
- ** the control in the control list. The first control in the list is
- ** control #1. Again, this is only for the case where the assigned ctlID
- ** is 0.
- ** This code implements the 7.0 human-interface standards for both TextEdit and
- ** List controls. These standards include the following features:
- **
- ** 1) Tabbing between TextEdit and List controls within a window.
- ** 2) Displaying what item is active. The active TextEdit item is indicated
- ** by either a blinking caret, or a selection range.
- ** 3) List positioning via the keyboard. Entries on the keyboard automatically
- ** select and display the closest List item. Also, the up and down arrows
- ** scroll through the list.
- ** 4) Document window scrollbars are handled.
- ** 5) Balloon help for window contents is handled (when called with a NULL event).
- **
- ** The main call for handling the control events is:
- ** short IsCtlEvent(WindowPtr window, EventRecord *event,
- ** ControlHandle *retCtl, short *retAction);
- **
- ** This call handles the following:
- ** 1) Document scrolling.
- ** 2) TextEdit control events.
- ** 3) List control events.
- ** 4) Tabbing (and shirt-tabbing) between TextEdit and list controls.
- ** 5) Displaying the selected TextEdit or List control.
- ** 6) Buttons.
- ** 7) Radio buttons.
- ** 8) Check boxes.
- ** 9) Popups and other controls.
- ** 10) Balloon help for controls.
- **
- ** The document content is scrolled automatically. The updateRgn is set to include the
- ** area scrolled into view and the window update procedure is automatically called.
- **
- ** TextEdit and List control events are completely handled. Since the controls are just
- ** containers for TERecords or ListRecords, all other access is up to the application.
- **
- ** Simple buttons are simply tracked.
- **
- ** Radio buttons are updated to reflect the new selection. Radio buttons are handled as
- ** families. The refCon field holds the family number. For any given family, there can
- ** only be one selected radio button. When a new one is clicked on, the old selected
- ** radio button is deselected automatically.
- **
- ** Check boxes are simply toggled on and off, as there is no family relationship between
- ** checkboxes.
- **
- ** Popups are simply tracked. To determine what the popup choice is, the popup control
- ** value will have to be retreived.
- **
- ** The return value of IsCtlEvent is non-zero if the event was handled. The values are
- ** as follows:
- **
- ** 0x8000: IsCtlEvent scrolled the document. The constant kScrollEvent is
- ** defined as 0x8000 for this purpose.
- ** 0: IsCtlEvent didn't handle the event.
- ** any other value: The control number of the control that handled the event. Remember that
- ** a TextEdit control may actually consist of up to 3 controls. There is
- ** the main container control for the TERecord. There may also be 1 or 2
- ** scrollbar controls that are related to the TERecord. The control number
- ** reflects which control was hit. This allows determination as to whether
- ** or not the scrollbar was hit.
- ** For TextEdit and list controls, even if a related scrollbar was hit, the
- ** control handle returned is the handle for the TextEdit control.
- **
- ** Just because a control number was returned doesn't mean that a control handle was returned.
- ** If an inactive scrollbar is clicked on, then FindControl returns nil, instead of the
- ** control handle (really). The control that is returned is what FindControl returns, and
- ** therefore it is possibly nil.
- **
- ** For TextEdit and List controls, IsCtlEvent simply calls CTEClick, CTEKey, CLClick or
- ** CLKey. The value returned as the action depends on which function was called. The
- ** true/false returned by these functions as to whether or not the control handled the event
- ** is expanded to be the control number. If false is returned by any of these functions, then
- ** IsCtlEvent returns 0 for the control number.
- **
- ** IsCtlEvent has no way of determining if you are actually using TextEdit or List controls.
- ** Since it has to make function calls service these controls, code may get linked into your
- ** application that you don't need. To prevent this, IsCtlEvent calls the appropriate
- ** functions by function pointer. The default functions are just stub functions that return
- ** appropriate results as if there were no such controls. This allows IsCtlEvent to handle
- ** the case where these controls aren't used without linking in a bunch of code.
- **
- ** So what about the case where you DO want to use these controls? To create one of these
- ** controls, you have to call either CTENew or CLNew, for TextEdit and List controls,
- ** respectively. (Or, if you are using the AppsToGo program editor, you simply create them
- ** in a fashion similar to ResEdit.)
- **
- ** When CTENew is called, it calls CTEInitialize. CTEInitialize replaces all
- ** of the stub function procedure pointers with pointers to the actual functions.
- ** If you call CTENew, then CTENew will get linked in. Since CTENew calls
- ** CTEInitialize, CTEInitialize will get linked in. Since it references the actual
- ** code, the actual code will get linked in. This allows you to not have to worry about
- ** specific implementations linking in too much code. If you call it, it will link. The
- ** above process is also done for List controls. */
-
-
-
- short CNum2Ctl(WindowPtr window, short ctlNum, ControlHandle *ctl);
- /*
- ** ¶ Convert a control number to a control handle.
- **
- ** INPUT: window Window that owns the control list to be scanned.
- ** ctlNum ID of the control to search for.
- ** OUTPUT: ctl If a control is found with the correct ID, it is returned here.
- ** RESULT: short ID of found control (archaic)
- **
- ** AppsToGo extends the control record. This means that, among other things, controls
- ** can have a fixed control ID. If a control has a style, and the ctlID field if the
- ** style is non-zero, then that control has a fixed control ID. Due to this, CNum2Ctl
- ** first scans all of the controls for a control with a style that has the designated
- ** ctlID. If one is found, then that's the control returned. If none is found, then
- ** the behavior for this function is as before (for the purpose of backwards-compatibility).
- **
- ** The way that this function used to work is:
- **
- ** It simply walks the window's control list counting down until it has reached
- ** the right control number. It also returns the number of controls traversed.
- ** While often this will be the same as the control number passed in, if the
- ** number passed in is greater than the number of controls in the list, then
- ** the number returned is the number of controls in the list. */
-
-
-
- short Ctl2CNum(ControlHandle ctl);
- /*
- ** ¶ Convert a control handle to a control number.
- **
- ** INPUT: ctl Control handle to convert to an ID.
- ** RESULT: short The ID of the control passed in.
- **
- ** This function converts a control handle to a control number. This allows you to convert
- ** what is normally a runtime variable into something that can be equated to a constant,
- ** thus allowing you to code your control handling into case statements. This function
- ** does the opposite of CNum2Ctl. */
-
-
-
- void DoCtlActivate(WindowPtr window);
- /*
- ** ¶ Reactivate a TextEdit or List control.
- **
- ** INPUT: window Window whose TextEdit or List control is to be reactivated
- **
- ** This reactivates the TextEdit or List control that was active for a particular window.
- ** When a window is moved from the front, the controls are supposed to become inactive.
- ** This is handled, but the control that was last active for a window is remembered.
- ** When the window is brought to the front, that particular control can be reactivated
- ** by calling DoCtlActivate. */
-
-
-
- void GetCheckBoxValues(WindowPtr window, Boolean checkBoxVal[]);
- /*
- ** ¶ Return checkBox values, en-masse.
- **
- ** INPUT: window Window whose control list is to be scanned for
- ** checkBox controls.
- ** OUTPUT: checkBoxVal An array that is to receive the value of the checkBox
- ** controls in the windowList. It is the caller's
- ** responsibility to guarantee that the array is large enough.
- ** This function will use one array element for every
- ** checkBox control found in the control list of the window.
- **
- ** Call this to scan the window’s control list for checkbox controls. For each one
- ** found, you need an element in the array. The entire control list is scanned. The
- ** control ID is ignored. Only the order in the control list is relavent. What this
- ** means in terms of the AppsToGo editor is that the checkbox control that is back-most
- ** has it’s value returned in element 0. */
-
-
-
- short GetRadioButtonChoice(WindowPtr window, short famNum);
- /*
- ** ¶ Determine which radio button is selected in a family.
- **
- ** INPUT: window Window containing the family of radio buttons.
- ** famNum The family number of the radio buttons.
- ** RESULT: short Which radio button in the family that is selected.
- **
- ** Given a particular family number, return which radio button is the currently selected
- ** button. If the requested family isn't found, or there are no selected radio buttons
- ** in the family, -1 is returned. If the family is found, the control number of the the
- ** selected radio button minus the control number of the first in the family is returned.
- ** ••• The first in the family is the control with the smallest ID. •••
- ** This means that for most situations, you will simply get an integer from 0-N for the
- ** radio button selection, as in most cases, the radio button ID's will be sequential in
- ** the control list. */
-
-
-
- ControlHandle CDataNext(WindowPtr window, ControlHandle ctl);
- /*
- ** ¶ Iterate to the next data control.
- **
- ** INPUT: window Window containing control list to scan.
- ** ctl Control to start search from (nil for beginning of list)
- ** RESULT: ControlHandle Next data control in list (nil indicates no more in list)
- **
- ** When a set of controls defined with the AppsToGo editor is added to a window, an
- ** additional Data control is also added. The purpose of the Data control is to keep
- ** track of which controls were added as a set of controls. (The Data control "groups"
- ** the set of controls.) CDataNext allows you to get the next data control out of the
- ** window's control list. (Normally you won't need this function.) */
-
-
-
- Boolean ControlBalloonHelp(WindowPtr window, short modifiers, Point mouseLoc);
- /*
- ** ¶ Handle balloon help for controls.
- **
- ** INPUT: window Window containing controls that may have balloon help info.
- ** modifiers This is in case the application is using fast balloons.
- ** mouseLoc Current mouse location, in global coordinates.
- ** RESULT: Boolean True if a balloon was displayed.
- **
- ** This function is actually in Help.c, but it is specifically for managing
- ** balloon help for controls. IsCtlEvent calls it, although you can call it
- ** yourself, if you want. (There shouldn't be any reason for an application
- ** to call this directly. */
-
-
-
- ControlHandle ControlBalloonMessage(WindowPtr window, Point mouseLoc, HMMessageRecord *msg,
- Rect *msgRct, short *pos, short *hrctID, short *itemID);
- /*
- ** ¶ Get the balloon help record for a control.
- **
- ** INPUT: window Window containing controls that may have balloon help info.
- ** mouseLoc
- ** OUTPUT: msg The Balloon Help message record. This is what should be
- ** displayed in the balloon.
- ** msgRct The rect of the control the help message relates to.
- ** pos The balloon position.
- ** hrctID The 'hrct' resource ID.
- ** itemID The 'hrct' resource item ID.
- ** RESULT: ControlHandle The control the help is for. */
-
-
-
- PicHandle BalloonText2PICT(WindowPtr window, HMMessageRecord *msg);
- /*
- ** ¶ Convert the too-big text to a PICT so it can be displayed.
- **
- ** INPUT: window Window that the balloon help is for.
- ** msg The Balloon Help message record. (May or may not be a text record.)
- ** RESULT: PicHandle If the Balloon Help record is text, then a PicHandle is created
- ** that contains the text.
- **
- ** This function converts a Balloon Help text message into a PicHandle. This is because
- ** Balloon Help only automatically works for text strings less than 255 characters.
- ** Longer balloons need to be done with the PICT resource type. This function converts
- ** text messages into a PICT so that long text can be used without having to create
- ** a PICT. */
-
- #endif
-